global root "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"
//global rootbrad "W:/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"
global results "$root/07_results/RR/main"
global dictionaries "$root/Dictionaries"

cd "$dictionaries"
capture log close
log using preliminary_regressions, replace

cd "$root"

use appended_analytic_010305111719, clear 
//use fd_appended_analytic_010305111719, clear 

drop if education_head==.

//bysort year: sum taxprice
/*
replace whether_donation_religious=0 if whether_donation_religious==5
replace whether_donation_combo=0 if whether_donation_combo==5
replace whether_donation_needy=0 if whether_donation_needy==5
replace whether_donation_health=0 if whether_donation_health==5
replace whether_donation_education=0 if whether_donation_education==5
replace whether_donation_youth=0 if whether_donation_youth==5tab 
replace whether_donation_culture=0 if whether_donation_culture==5
replace whether_donation_community=0 if whether_donation_community==5
replace whether_donation_environment=0 if whether_donation_environment==5
replace whether_donation_peace=0 if whether_donation_peace==5
replace whether_donation_other=0 if whether_donation_other==5

replace whether_donation_religious=0 if whether_donation_religious==.a
replace whether_donation_combo=0 if whether_donation_combo==.a
replace whether_donation_needy=0 if whether_donation_needy==.a
replace whether_donation_health=0 if whether_donation_health==.a
replace whether_donation_education=0 if whether_donation_education==.a
replace whether_donation_youth=0 if whether_donation_youth==.a
replace whether_donation_culture=0 if whether_donation_culture==.a
replace whether_donation_community=0 if whether_donation_community==.a
replace whether_donation_environment=0 if whether_donation_environment==.a
replace whether_donation_peace=0 if whether_donation_peace==.a
replace whether_donation_other=0 if whether_donation_other==.a


//bysort year: sum taxprice

gen whether_donation=.
replace whether_donation=0 if whether_donation_religious==0 & whether_donation_combo==0 & whether_donation_needy==0 & whether_donation_health==0 & whether_donation_education==0 & whether_donation_youth==0 & whether_donation_culture==0 & whether_donation_community==0 & whether_donation_environment==0 & whether_donation_peace==0 & whether_donation_other==0

replace whether_donation=1 if whether_donation_religious==1 | whether_donation_combo==1 | whether_donation_needy==1 | whether_donation_health==1 | whether_donation_education==1 |whether_donation_youth==1 | whether_donation_culture==1 | whether_donation_community==1 | whether_donation_environment==1 | whether_donation_peace==1 | whether_donation_other==1 
*/

* Temporary code***
//replace hours_volunteer_person = min(hours_volunteer_person, 2080) if hours_volunteer_person ~=.

bysort unique_id_crossys: egen ever_given=max(total_giving)
generate whether_donation=.
replace whether_donation=0 if ever_given==0
replace whether_donation=1 if ever_given>0

label var whether_donation "Donated Money"

eststo ext_margin_pooled_don: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if whether_donation==1, absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 3300 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_pooled_ndon: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if whether_donation==0, absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 4095 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_singlem_don: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & sequence_num==1 & married==0 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)    
// (dropped 1524 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_singlem_ndon: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & sequence_num==1 & married==0 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 2140 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_singlef_don: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & sequence_num==1 & married==0 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 2371 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_singlef_ndon: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & sequence_num==1 & married==0 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 2617 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_marriedm_don: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & married==1 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 3586 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_marriedm_ndon: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & married==1 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 2136 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_marriedf_don: reghdfe whether_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 3609 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo ext_margin_marriedf_ndon: reghdfe whether_volunteer_person   taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals


/////////////////////////////////////////////////////////////////////////////////////////////////

drop if year==2010
drop if hours_volunteer_person==0


eststo int_margin_pooled_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age sex married   black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural  if whether_donation==1, absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 3891 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_pooled_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age sex married     black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if whether_donation==0, absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 3277 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlem_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & sequence_num==1 & married==0 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1056 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlem_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & sequence_num==1 & married==0 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1249 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlef_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & sequence_num==1 & married==0 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1694 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlef_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age  black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & sequence_num==1 & married==0 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1632 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedm_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & married==1 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 3290 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedm_ndon: reghdfe hours_volunteer_person taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & married==1 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1394 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedf_don: reghdfe hours_volunteer_person taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 3299 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedf_ndon: reghdfe hours_volunteer_person taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1410 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

cd "$results"

	 esttab ext_margin_pooled_don  ext_margin_singlem_don  ext_margin_singlef_don  ext_margin_marriedm_don  ext_margin_marriedf_don using "ext_donated_mstatus_replication_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) addnotes("Outcome Variable: Hours Volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))
	 
	 	 esttab  ext_margin_pooled_ndon  ext_margin_singlem_ndon  ext_margin_singlef_ndon  ext_margin_marriedm_ndon  ext_margin_marriedf_ndon using "ext_ndonated_mstatus_replication_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) addnotes("Outcome Variable: Hours Volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))

		 	 esttab int_margin_pooled_don  int_margin_singlem_don  int_margin_singlef_don  int_margin_marriedm_don  int_margin_marriedf_don using "int_donated_mstatus_replication_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3)  addnotes("Outcome Variable: Hours Volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))
	 
	 	 esttab  int_margin_pooled_ndon  int_margin_singlem_ndon  int_margin_singlef_ndon  int_margin_marriedm_ndon  int_margin_marriedf_ndon using "int_ndonated_mstatus_replication_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) addnotes("Outcome Variable: Hours Volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))
stop
		 
//////////////////////////////////////////////////////////////////////////////////////////////////




// (dropped 2138 singleton observations)

drop if year==2010


eststo int_margin_pooled_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if whether_donation==1, absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 3891 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_pooled_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if whether_donation==0, absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 3277 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlem_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & sequence_num==1 & married==0 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1056 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlem_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & sequence_num==1 & married==0 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1249 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlef_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & sequence_num==1 & married==0 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1694 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_singlef_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & sequence_num==1 & married==0 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1632 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedm_don: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & married==1 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 3290 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedm_ndon: reghdfe hours_volunteer_person  taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==1 & married==1 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1394 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedf_don: reghdfe hours_volunteer_person taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1 & whether_donation==1), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 3299 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

eststo int_margin_marriedf_ndon: reghdfe hours_volunteer_person taxprice post_tax_income  hourly_wage_aftertax full_time   age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1 & whether_donation==0), absorb(year state unique_id_crossys) vce(cluster state)  
// (dropped 1410 singleton observations)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

cd "$results"

	 esttab ext_margin_pooled_don ext_margin_singlem_don ext_margin_singlef_don ext_margin_marriedm_don ext_margin_marriedf_don using "regress_ext_donated_mstatus_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) title("Extensive Margin - Subsample who Donated") addnotes("Outcome Variable: Whether volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))
	 
	 	 esttab ext_margin_pooled_ndon ext_margin_singlem_ndon ext_margin_singlef_ndon ext_margin_marriedm_ndon ext_margin_marriedf_ndon using "regress_ext_ndonated_mstatus_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) title("Extensive Margin - Subsample who Did not Donate") addnotes("Outcome Variable: Whether volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))
	 
	 
	 esttab int_margin_pooled_don int_margin_singlem_don int_margin_singlef_don int_margin_marriedm_don int_margin_marriedf_don using "regress_int_donated_mstatus_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) title("Intensive Margin - Subsample who Donated") addnotes("Outcome Variable: Hours Volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))
	 
	 	 esttab int_margin_pooled_ndon int_margin_singlem_ndon int_margin_singlef_ndon int_margin_marriedm_ndon int_margin_marriedf_ndon using "regress_int_ndonated_mstatus_RR2.rtf", se star(* 0.10 ** 0.05 *** 0.01) keep(taxprice) replace se(a4) b(a3) title("Intensive Margin - Subsample who Did not Donate") addnotes("Outcome Variable: Hours Volunteered" "State, Year, and Household FE included") modelwidth(12) label mtitle("Pooled" "Single Males" "Single Females" "Married Males" "Married Females") cells(b(star fmt(3)) se(par fmt(3)))

	cd "$dictionaries"
log close
